import { reqGetDetailList ,reqAddToCart} from "@/api"
const state ={
    detailList:{}
}
const actions ={
   async getDetailList({commit},skuId){
       let result = await reqGetDetailList(skuId);
       if(result.code == 200){
           commit('GETDETAILLIST',result.data)
       }
   },
   async addShopCart({commit},{skuId,skuNum}){
       let result = await reqAddToCart(skuId,skuNum);
       if(result.code == 200){
           console.log(111)
           return 'ok'
       }else{
           return Promise.reject(new Error('faile'));
       }
   }
}
const mutations ={
    GETDETAILLIST(state,detailList){
            state.detailList = detailList
    }
}
const getters = {
    categoryView(state){
        return state.detailList.categoryView||{}
    },
    // 商品属性的值
    spuSaleAttrList(state){
        return state.detailList.spuSaleAttrList;
    },
    skuInfo(state){
        return state.detailList.skuInfo||{}
    }
}
export default {
    state,
    actions,
    mutations,
    getters
}